﻿using ABCNet.Authorization.Users;
using Abp.Runtime.Session;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABCNet
{
    public static class IAbpSessionExtensions
    {
        /// <summary>
        /// 获取账户类型
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public static AccountTypes GetAccountType(this IAbpSession session)
        {
            var claimsPrincipal =  DefaultPrincipalAccessor.Instance.Principal;
            var accountTypeClaim = claimsPrincipal?.Claims.FirstOrDefault(c => c.Type == "AccountType");
            if (string.IsNullOrEmpty(accountTypeClaim?.Value))
                return AccountTypes.会员账户;
            if (int.TryParse(accountTypeClaim.Value, out int accountType))
            {
                return (AccountTypes)accountType;
            }
            return AccountTypes.会员账户;
        }
    }
}
